package org.soft.carbon_neutral.controller;

import com.alibaba.fastjson.JSON;
import org.soft.carbon_neutral.entity.Equipment;
import org.soft.carbon_neutral.service.impl.EquipmentServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/equipment")
@CrossOrigin
public class EquipmentController {

    @Autowired
    private EquipmentServiceImpl equipmentService;

    @GetMapping("/selectAll")
    public String selectAll() {
        return JSON.toJSONString(equipmentService.selectAll());
    }

    @GetMapping("/getAllEquipmentValue")
    public String getAllEquipmentValue() {return JSON.toJSONString(equipmentService.getAllEquipmentValue());}

    @GetMapping("/selectOneById/{id}")
    public String selectOneById(@PathVariable("id") String id) {
        return JSON.toJSONString(equipmentService.selectOneById(id));
    }

    @PostMapping("/updateOneById")
    public String updateOneById(@RequestBody Equipment equipment) {
        return JSON.toJSONString(equipmentService.updateOneById(equipment));
    }

    @PutMapping("/removeOneById/{id}")
    public String removeOneById(@PathVariable("id") String id) {
        return JSON.toJSONString(equipmentService.removeOneById(id));
    }

    @PostMapping("/addEquipment/{type}")
    public String addEquipment(@RequestBody Equipment equipment, @PathVariable("type") String type) {
        return JSON.toJSONString(equipmentService.addEquipment(equipment,type));
    }

}
